package com.coolbi.onsupai.core.util;

import java.util.ArrayList;
import java.util.List;

import com.coolbi.common.util.CommonUtil;
import com.coolbi.onsupai.core.entity.GoodsInfo;

/**
 * @Description 商品工具类
 * @author for2cold
 * @codeDate 2012-8-18 下午06:40:35
 *
 */
public class GoodsUtils {

	/**
	 * 将id quantity price封装成商品集合
	 * @param ids
	 * @param quantitys
	 * @param prices
	 * @return
	 */
	public static List<GoodsInfo> encapsulList(String ids, String prices, String stocks) {
		List<GoodsInfo> goodsInfos = new ArrayList<GoodsInfo>();
		GoodsInfo goodsInfo = null;
		long[] idsArray = CommonUtil.parseToLong(ids, ", ");
		long[] stocksArray = CommonUtil.parseToLong(stocks, ", ");
		double[] priceArray = CommonUtil.parseToDouble(prices, ", ");
		int length = priceArray.length;
		for (int i = 0; i < length; i ++) {
			goodsInfo = new GoodsInfo();
			goodsInfo.setId(idsArray[i]);
			goodsInfo.setRecentPrice(priceArray[i]);
			goodsInfo.setStock(stocksArray[i]);
			goodsInfo.setEnableStock(stocksArray[i]);
			goodsInfos.add(goodsInfo);
		}
		return goodsInfos;
	}
}
